package com.gree.ssm.web.admin;

import com.gree.ssm.bean.BlogType;
import com.gree.ssm.common.CommonResult;
import com.gree.ssm.service.BlogTypeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContextUtils;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author :xiaossong
 * @Description:管理员系统Controller层
 * @Date Created in 下午11:00 2017/10/18
 */
@Controller
@RequestMapping("/admin/system")
public class SystemAdminController {

    @Resource
    private BlogTypeService blogTypeService;
    /**
     * 刷新系统缓存
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/refreshSystem")
    public CommonResult refreshSystem(HttpServletResponse response, HttpServletRequest request)throws Exception{
        //适合2.5版本使用
        //ServletContext application= RequestContextUtils.getWebApplicationContext(request).getServletContext();
        ServletContext application = request.getServletContext();
        //Blogger blogger=bloggerService.find(); // 查询博主信息
       // blogger.setPassword(null);
       // application.setAttribute("blogger", blogger);

        List<BlogType> blogTypeCountList=blogTypeService.countList(); // 查询博客类别以及博客的数量
        application.setAttribute("blogTypeCountList", blogTypeCountList);

        //List<Blog> blogCountList=blogService.countList(); // 根据日期分组查询博客
        //application.setAttribute("blogCountList", blogCountList);

        //List<Link> linkList=linkService.list(null); // 获取所有友情链接
        //application.setAttribute("linkList", linkList);


        return new CommonResult(1002,"success");
    }

}
